package 笔试.暑期2023.腾讯音乐2022_暑期招聘;

import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;

public class T4_Solution {
    public int howMany (String s, int k) {
        int len = s.length();
        if(len<k){
            return 0;
        }
        // 创建Map进行统计
        char[] ch = s.toCharArray();
        HashMap<Character, Integer> map = new HashMap(26);
        for(int i=0; i<len; i++){
            Character temp = new Character(ch[i]);
            map.put(temp, map.containsKey(temp) ? map.get(temp)+1 : 1);
        }
        // 统计
        AtomicInteger count = new AtomicInteger();
        map.forEach((key,value)->{
            if(value > k){
                count.getAndIncrement();
            }
        });
        return count.get();
    }
}